home *** CD-ROM | disk | FTP | other *** search
- Program Pas_to_ResCode_LDEF;
- {**** Written and © 1989 by Shelly Mendlinger ****}
- {**** Brooklyn, New York ****}
-
- uses
- memtypes,
- quickdraw,
- osintf,
- toolintf,
- packintf;
- const
- resFile = 'PatList.rsrc';
- RType = 'LDEF';
- resID = 1000;
- resName = 'PatList Def';
- var
- CodePtr : procPtr;
- CodeHand : handle;
- CodeSize : size;
- oldResNum,
- newResNum,
- err : integer;
- str : str255;
- goAhead : boolean;
-
- {*** This Proc is turned into res code ***}
- Procedure theCode(Message : integer;
- isSelect : boolean;
- cRect : rect;
- theCell : cell;
- LDataOffSet,
- LdataLen : integer;
- aList : Listhandle);
- type
- patPtr = ^pattern;
- var
- aPat : patPtr;
- oldClip : rgnHandle;
- hand : handle;
- aRect : rect;
- begin
- {--- what's the story ---}
- case Message of
-
- LInitMsg: {initialize the list}
- begin
- {--- select one cell at a time ---}
- aList^^.selFlags := LOnlyOne;
- {--- frame the list ---}
- Pennormal;
- aRect := aList^^.rView;
- inSetRect(aRect,-1,-1);
- framerect(aRect);
- end;{init}
-
- LdrawMsg: {draw theCell}
- begin
- {--- save port's cliprgn ---}
- oldclip := aList^^.port^.cliprgn;
- {--- change port's cliprgn, IM says so ---}
- rectRgn(aList^^.port^.cliprgn,cRect);
- {--- calc cell's data address ---}
- Hand := handle(aList^^.cells); {handle to data}
- aPat := patPtr(pointer(ord(hand^) + LDataOffSet)); {ptr to pat}
- {--- draw cell frame & pat ---}
- framerect(cRect);
- aRect := cRect;
- inSetRect(aRect,5,5);
- FillRect(aRect,aPat^);
- FrameRect(aRect);
- {--- restore port's clip ---}
- aList^^.port^.cliprgn := oldClip;
- end;{draw}
-
- LHiliteMsg: {hilite theCell}
- begin
- {--- same clip stuff as above --}
- oldclip := aList^^.port^.cliprgn;
- rectRgn(aList^^.port^.cliprgn,cRect);
- {--- Xor a frame ---}
- pennormal;
- penMode(patXor);
- penSize(4,4);
- aRect:= cRect;
- inSetRect(aRect,-5,-5);
- frameRect(cRect);
- pennormal;
- {--- clip stuff ---}
- aList^^.port^.cliprgn := oldClip;
- end;{hilite}
- otherwise
- end;{case message}
- end;{proc theCode}
-
- {--- mark the end of theCode ---}
- Procedure Marker;
- begin
- end;{proc mark}
-
- Procedure EventLoop;
- var
- evt : eventRecord;
- GetOut : boolean;
- begin
- GetOut := false;
- repeat
- if getNextEvent(everyevent,evt) then
- case evt.what of
- {--- any key to quit ---}
- keyDown : GetOut := true;
- {--- click to proceed ---}
- mouseDown : GoAhead := true;
- otherwise
- end;{case what}
- until GetOut or GoAHead;
- end;{proc eventloop}
-
- Begin {main}
- {--- address of theCode ---}
- CodePtr := @theCode;
- {--- pointer math ---}
- CodeSize := size(ord(@Marker) - ord(codePtr));
- {--- get handle for AddResource ---}
- Err := PtrToHand(CodePtr,CodeHand,CodeSize);
- if err <> noErr then
- begin
- numtoString(err,str);
- str := 'OS ERROR GETTING HANDLE. #' + str;
- moveto(100,100);
- drawstring(str);
- end { error}
- else
- begin
- goAhead := false;
- {--- save current res fie ---}
- oldResNum := curResfile;
- {--- draw interface ---}
- textfont(0);
- textsize(18);
- moveto(20,25);
- drawstring('ANY KEY TO QUIT');
-
- moveto(20,55);
- drawstring('CLICK TO ADD RESOURCE');
-
- str := 'Res File: ' + ResFile;
- moveto(100,75);
- drawstring(str);
-
- str := 'Res Type: ' + RType;
- moveto(100,95);
- drawstring(str);
-
- numtostring(ResID,str);
- str := 'Res Id: ' + str;
- moveto(100,115);
- drawstring(str);
-
- str := 'Res Name: ' + ResName;
- moveto(100,135);
- drawstring(str);
-
- numtostring(CodeSize,str);
- str := 'Code size: ' + str + ' bytes';
- moveto(100,155);
- drawstring(str);
-
-
- EventLoop;
-
- if GoAhead then
- begin
-
- {******* OPTIONAL. If neened,usually done once***}
- createResFile(resFile);
- {******* then new resCode &ID added to file ****}
-
- {--- open res file --}
- newResNum := openResFile(ResFile);
- {--- write to res file ---}
- addResource(CodeHand,RType,resID,ResName);
- {--- close selected res file ---}
- closeresFile(newResNum);
- {--- restore orig. res file ---}
- useResFile(oldResNum);
- end;{do it}
- end;{else no err}
- end.{prog pas to res code}
-
-
-
-